package com.fare.taluo.application.impl.report.careport;

import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.NumberFormats;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.report.careport.ReportOTADomesticApplication;
import com.fare.taluo.application.report.careport.ReportStaticData;
import com.fare.taluo.core.domain.config.channel.SourceEntity;
import com.fare.taluo.fetl.domain.entity.AirChinaDomesticEntity;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.core.FlightInfoVO;
import com.fare.taluo.vo.core.TaskInfoEntityVO;
import com.fare.taluo.vo.report.AirChinaDemesticReportVO;

@Transactional
@Scope("singleton")
@Service("reportOTADomesticApplication")
public class ReportOTADomesticApplicationImpl implements
		ReportOTADomesticApplication {
	
	
	private List<SourceEntity> listSourceEntity;
	
	@Override
	public void createExcelforOTA(List<TaskInfoEntityVO> list,OutputStream os) throws Exception {
			Map<String ,Map<String ,List<AirChinaDemesticReportVO>>> map =this.getListAirChina(list);
			Calendar calendar=Calendar.getInstance(); 
			int count = calendar.get(Calendar.DAY_OF_WEEK);
			
			WritableWorkbook wwb =null;
			//Map<String, List<Integer>> backgroundColor= ReportStaticData.getOTADomesticColor(); //背景为黄色的行数
			
			try{
				 wwb = Workbook.createWorkbook(os); // 建立excel文件   
				 wwb.setColourRGB(Colour.PALE_BLUE, 75, 172, 198);//重写蓝色
				 wwb.setColourRGB(Colour.YELLOW, 255, 255, 0);//重写黄色
				 
		        //定义样式
		        jxl.write.WritableFont normalFont = new jxl.write.WritableFont(WritableFont.createFont("宋体"), 10);
			    jxl.write.WritableCellFormat  normalFormat = new jxl.write.WritableCellFormat(normalFont);
			    normalFormat.setBorder(Border.ALL, BorderLineStyle.THIN); 
			    normalFormat.setVerticalAlignment(VerticalAlignment.CENTRE); 
			    normalFormat.setAlignment(Alignment.CENTRE); 
			    normalFormat.setBackground(Colour.PALE_BLUE);// 背景蓝色
			    normalFormat.setWrap(false);
			    
			    
			    jxl.write.WritableFont normalFont1 = new jxl.write.WritableFont(WritableFont.createFont("宋体"), 10);
			    jxl.write.WritableCellFormat  colgFormat = new jxl.write.WritableCellFormat(normalFont1);
			    colgFormat.setBorder(Border.ALL, BorderLineStyle.THIN); 
			    colgFormat.setVerticalAlignment(VerticalAlignment.CENTRE); 
			    colgFormat.setAlignment(Alignment.CENTRE); 
			    colgFormat.setBackground(Colour.YELLOW);// 背景黄色
			    colgFormat.setWrap(false);
			    
			    jxl.write.WritableCellFormat blueWcfN = new jxl.write.WritableCellFormat(NumberFormats.TEXT);
			    blueWcfN.setBorder(Border.ALL, BorderLineStyle.THIN); 
			    blueWcfN.setVerticalAlignment(VerticalAlignment.CENTRE); 
			    blueWcfN.setAlignment(Alignment.CENTRE); 
			    blueWcfN.setBackground(Colour.PALE_BLUE);// 背景蓝色
			    
			    
			    jxl.write.WritableCellFormat colgWcfN = new jxl.write.WritableCellFormat(NumberFormats.TEXT);
			    colgWcfN.setBorder(Border.ALL, BorderLineStyle.THIN); 
			    colgWcfN.setVerticalAlignment(VerticalAlignment.CENTRE); 
			    colgWcfN.setAlignment(Alignment.CENTRE); 
			    colgWcfN.setBackground(Colour.YELLOW);// 背景黄色
			    
			 /*   grabStartDate =new Date();
	        	grabEndDate =DateUtils.strToDate(datetype, "yyyy-MM-dd");*/
	        	
			    int index = -1;
			    for(TaskInfoEntityVO vo :list){
			    	index++;
			    	String data =vo.getFromCity()+"-" +vo.getToCity();
			    	WritableSheet ws = wwb.createSheet(data, index); // sheet名称  
			//    	List<Integer> color =backgroundColor.get(data);
		        	ws = setHead(ws,data,count);//生成表头
		        	int row=2;
		        	Map<String ,List<AirChinaDemesticReportVO>> mapAir =map.get(data);
		        	List<FlightInfoVO> listvo =findFlightNoList(vo);
		        	String[] typeList = {"头等舱","公务舱","经济舱"};
		        	for(int i=0;i<typeList.length;i++){
		        			String type=typeList[i];
		        			List<AirChinaDemesticReportVO> listAir=mapAir.get(typeList[i]);
		        			if(null == listAir || listAir.size()==0){
		        				continue;
		        			}
			        	for(AirChinaDemesticReportVO flightvo :listAir){
			        		row ++;
			        		int FlightStartTimeInt =Integer.parseInt(flightvo.getFlightTime().substring(0,2));
			        		boolean isYellow =false;
			        		List<Integer> yellowrows=new ArrayList<Integer>();
			        		Collections.addAll(yellowrows, 0,1,2,3,4,5,6,7,8,12,13,14,18,19,20);
			        		isYellow=yellowrows.contains(FlightStartTimeInt);
			        		
//			        		for(int rowNo :color){
//			        			if(rowNo==row || (listvo.size()+rowNo+1)==row || (listvo.size()*2+rowNo+2)==row){
//			        				isYellow=true;
//			        			//	normalFormat.setBackground(Colour.GOLD);// 背景黄色
//			        				break;
//			        			}
//			        		}
			        		ws.setRowView(row, 400);
			        		ws.addCell(new Label(0,row,flightvo.getCompany(),isYellow?colgFormat:normalFormat));//公司
			        		ws.addCell(new  jxl.write.Number(1,row,Double.parseDouble(flightvo.getFlightNo()),isYellow?colgWcfN:blueWcfN));//航班号
			        		ws.addCell(new Label(2,row,flightvo.getFlightTime(),isYellow?colgFormat:normalFormat));//时刻
			        		ws.addCell(new Label(3,row,type,isYellow?colgFormat:normalFormat));//舱位
			        		
			        		
			        		
			        		if(count==2 && FlightStartTimeInt<=11){
			        			//如果为周一 且 航班时间小于excel表生成时间则设为空
			        			ws.addCell(new Label(4,row,"-",isYellow?colgFormat:normalFormat));
			        			ws.addCell(new Label(5,row,"-",isYellow?colgFormat:normalFormat));
			        			ws.addCell(new Label(6,row,"-",isYellow?colgFormat:normalFormat));
			        			ws.addCell(new Label(7,row,"-",isYellow?colgFormat:normalFormat));
			        			ws.addCell(new Label(8,row,"-",isYellow?colgFormat:normalFormat));
			   
			        		}else{
			        		
					        		
					        		if(flightvo.getPrice_1()<=0){
					        			ws.addCell(new Label(4,row,"-",isYellow?colgFormat:normalFormat));//官网	
					        		}else{
					        			ws.addCell(new jxl.write.Number(4,row,flightvo.getPrice_1(),isYellow?colgWcfN:blueWcfN));
					        		}
					        	
					        		if(flightvo.getCtripPrice_1()<=0){
					        			ws.addCell(new Label(5,row,"-",isYellow?colgFormat:normalFormat));//携程	
					        		}else{
					        			ws.addCell(new jxl.write.Number(5,row,flightvo.getCtripPrice_1(),isYellow?colgWcfN:blueWcfN));
					        		}
					        		
					        		if(flightvo.getCtripPrice_1()<=0 || flightvo.getPrice_1()<=0){
					        			ws.addCell(new Label(6,row,(flightvo.getCtripPrice_1()<=0 || flightvo.getPrice_1()<=0)?"-":Double.toString(flightvo.getCtripPrice_1()-flightvo.getPrice_1()),isYellow?colgFormat:normalFormat));//对比官网 携程-官网 
					        		}else{
					        			ws.addCell(new jxl.write.Number(6,row,flightvo.getCtripPrice_1()-flightvo.getPrice_1(),isYellow?colgWcfN:blueWcfN));
					        		}
					        		
					        		
					        		
					        		if(flightvo.getElongPrice_1()<=0){
					        			ws.addCell(new Label(7,row,"-",isYellow?colgFormat:normalFormat));//艺龙 	
					        		}else{
					        			ws.addCell(new jxl.write.Number(7,row,flightvo.getElongPrice_1(),isYellow?colgWcfN:blueWcfN));
					        		}
					        		
					        		if(flightvo.getElongPrice_1()<=0 || flightvo.getPrice_1()<=0){
					        			ws.addCell(new Label(8,row,"-",isYellow?colgFormat:normalFormat));//对比官网 艺龙-官网 
					        		}else{
					        			ws.addCell(new jxl.write.Number(8,row,flightvo.getElongPrice_1()-flightvo.getPrice_1(),isYellow?colgWcfN:blueWcfN));
					        		}
			        		}
				        		
//				        		ws.addCell(new Label(9,row,"",isYellow?colgFormat:normalFormat));//头等舱布局
//				        		ws.addCell(new Label(10,row,"",isYellow?colgFormat:normalFormat));//上坐率
				        	
				        		int cellSize=9;
				        		if(flightvo.getPrice_4()<=0){
				        			ws.addCell(new Label(cellSize,row,"-",isYellow?colgFormat:normalFormat));	
				        		}else{
				        			ws.addCell(new jxl.write.Number(cellSize,row,flightvo.getPrice_4(),isYellow?colgWcfN:blueWcfN));
				        		}
				        		cellSize++;
				        		if(flightvo.getCtripPrice_4()<=0){
				        			ws.addCell(new Label(cellSize,row,"-",isYellow?colgFormat:normalFormat));
				        		}else{
				        			ws.addCell(new jxl.write.Number(cellSize,row,flightvo.getCtripPrice_4(),isYellow?colgWcfN:blueWcfN));
				        		}
				        		cellSize++;
				        		if(flightvo.getCtripPrice_4()<=0 || flightvo.getPrice_4()<=0){
				        			ws.addCell(new Label(cellSize,row,"-",isYellow?colgFormat:normalFormat));
				        		}else{
				        			ws.addCell(new jxl.write.Number(cellSize,row,flightvo.getCtripPrice_4()-flightvo.getPrice_4(),isYellow?colgWcfN:blueWcfN));
				        		}
				        		cellSize++;
				        		if(flightvo.getElongPrice_4()<=0){
				        			ws.addCell(new Label(cellSize,row,"-",isYellow?colgFormat:normalFormat));
				        		}else{
				        			ws.addCell(new jxl.write.Number(cellSize,row,flightvo.getElongPrice_4(),isYellow?colgWcfN:blueWcfN));
				        		}
				        		cellSize++;
				        		if(flightvo.getElongPrice_4()<=0 || flightvo.getPrice_4()<=0){
				        			ws.addCell(new Label(cellSize,row,"-",isYellow?colgFormat:normalFormat));
				        		}else{
				        			ws.addCell(new jxl.write.Number(cellSize,row,flightvo.getElongPrice_4()-flightvo.getPrice_4(),isYellow?colgWcfN:blueWcfN));
				        		}
				        	
				        		
//				        		ws.addCell(new Label(16,row,"",isYellow?colgFormat:normalFormat));
//				        		ws.addCell(new Label(17,row,"",isYellow?colgFormat:normalFormat));
			        		
			        		
			        	}
			        
			        	row++;
			        	ws.setRowView(row, 400);
			        	ws.addCell(new Label(0,row,"",normalFormat));
			        	ws.addCell(new Label(1,row,"",normalFormat));
			        	ws.addCell(new Label(2,row,"",normalFormat));
			        	ws.addCell(new Label(3,row,"",normalFormat));
			        	ws.addCell(new Label(4,row,"",normalFormat));
			        	ws.addCell(new Label(5,row,"",normalFormat));
			        	ws.addCell(new Label(6,row,"",normalFormat));
			        	ws.addCell(new Label(7,row,"",normalFormat));
			        	ws.addCell(new Label(8,row,"",normalFormat));
			        	ws.addCell(new Label(9,row,"",normalFormat));
			        	ws.addCell(new Label(10,row,"",normalFormat));
			        	ws.addCell(new Label(11,row,"",normalFormat));
			        	ws.addCell(new Label(12,row,"",normalFormat));
			        	ws.addCell(new Label(13,row,"",normalFormat));
			        	
		        	}
			    }
			    wwb.write();
			    
			}catch(Exception e){
				System.out.println("生成Excel出错");
				throw new Exception(e);
			}finally{
				try {
					wwb.close();
				//	os.close();
				} catch (Exception e) {
					e.printStackTrace();
					throw new Exception(e);
				} 
			}
			
	}
	
	
	/**
	 * 根据航线获得航班列表
	 * @param taskInfoEntityVO
	 * @param dateType
	 * @return
	 */
	private List<FlightInfoVO> findFlightNoList(TaskInfoEntityVO taskInfoEntityVO){
		//Date date =DateUtils.strToDate(dateType, "yyyy-MM-dd");
		List<FlightInfoVO> list =new ArrayList<FlightInfoVO>();
		Map<String, List<String>> map=ReportStaticData.getOTADomesticFlight();//航线对应航班列表
		List<String> listFlight =map.get(taskInfoEntityVO.getFromCity()+"-"+taskInfoEntityVO.getToCity());
	/*	FlightInfoApplication lightInfoApplication =  InstanceFactory
				.getInstance(FlightInfoApplication.class);*/
		if(listFlight!=null && listFlight.size()>0){
			for(String flight:listFlight){
				boolean flag =false;
			/*	List<FlightInfoVO> listvo=lightInfoApplication.findByConditions("20006", taskInfoEntityVO.getFromCity(), taskInfoEntityVO.getToCity(), flight, date);
				if(listvo!=null){
					for(FlightInfoVO vo:listvo ){
						if(flight.equals(vo.getFlightNo())){
							list.add(vo);
							flag=true;
							break;
						}
					}
				}*/
				if(!flag){
					FlightInfoVO info = new FlightInfoVO();
					info.setFlightNo(flight);
					info.setFlightStartTime(ReportStaticData.getFlightStrTime().get(flight));
					list.add(info);
				}
			}
		}
		return list;
	}
	
	/**
	 * 设置excel表头
	 * */
	private WritableSheet setHead(WritableSheet ws,String flightLine,int count)throws Exception{
		Date  date =new Date();
		Calendar calendar=Calendar.getInstance();   
		calendar.setTime(date);
		String createTime =DateUtils.formatDay(date, "MM月dd日");
		String addOneDate=null;
		String addFourDate=null;
		if(count==2){
			addOneDate = "+0("+DateUtils.formatDay(date, "MM.dd")+")"; //如果是周一就 +0;
			calendar.add(Calendar.DAY_OF_MONTH, 4);
			addFourDate="+4("+DateUtils.formatDay(calendar.getTime(),"MM.dd")+")";
		}else{
			calendar.add(Calendar.DAY_OF_MONTH, 1);
			addOneDate="+1("+DateUtils.formatDay(calendar.getTime(),"MM.dd")+")";//+1
			calendar.add(Calendar.DAY_OF_MONTH, 3);
			addFourDate="+4("+DateUtils.formatDay(calendar.getTime(),"MM.dd")+")";
		}
		jxl.write.WritableFont titleFont = new jxl.write.WritableFont(
                WritableFont.createFont("宋体"), 15, WritableFont.BOLD);
		jxl.write.WritableCellFormat titleFormat = new jxl.write.WritableCellFormat(titleFont);
        titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
        titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
        titleFormat.setAlignment(Alignment.CENTRE); // 水平对齐
        titleFormat.setWrap(false); // 是否换行
        titleFormat.setBackground(Colour.WHITE);// 背景白色
        
        jxl.write.WritableFont titleFont1 = new jxl.write.WritableFont(
                WritableFont.createFont("宋体"), 12, WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.WHITE);
		jxl.write.WritableCellFormat titleFormat1 = new jxl.write.WritableCellFormat(titleFont1);
        titleFormat1.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
        titleFormat1.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
        titleFormat1.setAlignment(Alignment.CENTRE); // 水平对齐
        titleFormat1.setWrap(false); // 是否换行
        titleFormat1.setBackground(Colour.LIGHT_BLUE);// 背景蓝色
        
        jxl.write.WritableFont titleFont2 = new jxl.write.WritableFont(
                WritableFont.createFont("宋体"), 10, WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.WHITE);
		jxl.write.WritableCellFormat titleFormat2 = new jxl.write.WritableCellFormat(titleFont2);
        titleFormat2.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
        titleFormat2.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
        titleFormat2.setAlignment(Alignment.CENTRE); // 水平对齐
        titleFormat2.setWrap(false); // 是否换行
        titleFormat2.setBackground(Colour.LIGHT_BLUE);// 背景蓝色
        
        ws.setColumnView(0, 20);
       // ws.setRowView(0, 10);
        Label label_0_0 = new Label(0,0,"航线："+flightLine,titleFormat);
        ws.addCell(label_0_0);
        
        ws.mergeCells(1, 0, 13, 0);
        Label label_0_1 = new Label(1,0,createTime+"监控结果",titleFormat);
        ws.addCell(label_0_1);
        
        ws.mergeCells(0, 1, 0, 2);
        ws.setColumnView(0, 20);
        Label label_1_0 = new Label(0,1,"公司",titleFormat1);
        ws.addCell(label_1_0);
        
        ws.mergeCells(1, 1, 1, 2);
        ws.setColumnView(1, 10);
        Label label_1_1 = new Label(1,1,"航班号",titleFormat1);
        ws.addCell(label_1_1);
        
        ws.mergeCells(2, 1, 2, 2);
        ws.setColumnView(2, 10);
        Label label_1_2 = new Label(2,1,"时刻",titleFormat1);
        ws.addCell(label_1_2);
        
       
        ws.mergeCells(3, 1, 3, 2);
        ws.setColumnView(3, 10);
        Label label_1_3 = new Label(3,1,"舱位",titleFormat1);
        ws.addCell(label_1_3);
        ws.getSettings().setHorizontalFreeze(4);//固定列
        ws.getSettings().setVerticalFreeze(3);//固定行
        
        
        ws.mergeCells(4, 1, 8, 1);
        Label label_1_4 = new Label(4,1,addOneDate,titleFormat2);
        ws.addCell(label_1_4);
        
        ws.mergeCells(9, 1, 13, 1);
        Label label_1_5 = new Label(9,1,addFourDate,titleFormat2);
        ws.addCell(label_1_5);
        
        int cellSize=4;
        ws.setColumnView(cellSize, 10);
        Label label_2_4 = new Label(cellSize,2,"官网",titleFormat2);
        ws.addCell(label_2_4);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_5 = new Label(cellSize,2,"携程",titleFormat2);
        ws.addCell(label_2_5);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_6 = new Label(cellSize,2,"对比官网",titleFormat2);
        ws.addCell(label_2_6);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_7 = new Label(cellSize,2,"艺龙",titleFormat2);
        ws.addCell(label_2_7);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_8 = new Label(cellSize,2,"对比官网",titleFormat2);
        ws.addCell(label_2_8);
        cellSize++;
        
//        ws.setColumnView(9, 10);
//        Label label_2_9 = new Label(9,2,"头等舱布局",titleFormat2);
//        ws.addCell(label_2_9);
//        
//        ws.setColumnView(10, 10);
//        Label label_2_10 = new Label(10,2,"上坐率",titleFormat2);
//        ws.addCell(label_2_10);
        
        ws.setColumnView(cellSize, 10);
        Label label_2_11 = new Label(cellSize,2,"官网",titleFormat2);
        ws.addCell(label_2_11);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_12 = new Label(cellSize,2,"携程",titleFormat2);
        ws.addCell(label_2_12);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_13 = new Label(cellSize,2,"对比官网",titleFormat2);
        ws.addCell(label_2_13);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_14 = new Label(cellSize,2,"艺龙",titleFormat2);
        ws.addCell(label_2_14);
        cellSize++;
        
        ws.setColumnView(cellSize, 10);
        Label label_2_15 = new Label(cellSize,2,"对比官网",titleFormat2);
        ws.addCell(label_2_15);
        
//        ws.setColumnView(16, 10);
//        Label label_2_16 = new Label(16,2,"头等舱布局",titleFormat2);
//        ws.addCell(label_2_16);
//        
//        ws.setColumnView(17, 10);
//        Label label_2_17 = new Label(17,2,"上坐率",titleFormat2);
//        ws.addCell(label_2_17);
        
		return ws;
	}
	
	   
	   private   boolean isNumeric(String str){
			return str.matches("\\d*");    
		 } 
	   
	   private Map<String ,Map<String ,List<AirChinaDemesticReportVO>>> getListAirChina(List<TaskInfoEntityVO> list){
		   
		   Map<String ,Map<String ,List<AirChinaDemesticReportVO>>> map =new HashMap<String ,Map<String ,List<AirChinaDemesticReportVO>>>();
		   
		   for(TaskInfoEntityVO vo :list){
			   String data =vo.getFromCity()+"-" +vo.getToCity();
			   List<AirChinaDemesticReportVO> listPrimeAir =new ArrayList<AirChinaDemesticReportVO>();//头等舱
			   List<AirChinaDemesticReportVO> listBusiness =new ArrayList<AirChinaDemesticReportVO>();//公务舱
			   List<AirChinaDemesticReportVO> listEconomy =new ArrayList<AirChinaDemesticReportVO>();//经济舱
			   	Calendar calendar=Calendar.getInstance();   
				int count = calendar.get(Calendar.DAY_OF_WEEK);
				List<String> times =new ArrayList<String>();
				if(count==2){//周一
					String firstTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd"); //周一加0天
					times.add(firstTime);
					calendar.add(Calendar.DAY_OF_MONTH, 4);
					String secondTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd");//加4天
					times.add(secondTime);
				}else if(count==4){//周三
					calendar.add(Calendar.DAY_OF_MONTH, 1);
					String firstTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd");//周三加1天
					times.add(firstTime);
					calendar.add(Calendar.DAY_OF_MONTH, 3);
					String secondTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd");//周三加4天
					times.add(secondTime);
				}else{
					//return null;
					calendar.add(Calendar.DAY_OF_MONTH, 1);
					String firstTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd");
					times.add(firstTime);
					calendar.add(Calendar.DAY_OF_MONTH, 3);
					String secondTime = DateUtils.formatDay(calendar.getTime(), "yyyyMMdd");
					times.add(secondTime);
				}
				List<FlightInfoVO> listvo =findFlightNoList(vo);
				String rowkey=null;  //渠道_起点(使用三字码)_终点(使用三字码)_(航班号)_航班时间(年月日时) 
				for(FlightInfoVO flightvo :listvo){
					AirChinaDemesticReportVO primeAirVo =new AirChinaDemesticReportVO();
					AirChinaDemesticReportVO businessVo =new AirChinaDemesticReportVO();
					AirChinaDemesticReportVO economyVo =new AirChinaDemesticReportVO();
					SourceEntity sourceEntity =new SourceEntity();
					if(null==listSourceEntity || listSourceEntity.size()==0){
						listSourceEntity=sourceEntity.findAllSourceEntity();
					}
					for(SourceEntity e:listSourceEntity){
						if(flightvo.getFlightNo().substring(0, 2).equals(e.getCarrierKey())){
							sourceEntity=e;
							break;
						}
					}
					primeAirVo.setCompany(flightvo.getFlightNo().substring(0, 2));
					primeAirVo.setFlightNo(flightvo.getFlightNo().substring(2));
					primeAirVo.setFlightTime(flightvo.getFlightStartTime());
					
					businessVo.setCompany(flightvo.getFlightNo().substring(0, 2));
					businessVo.setFlightNo(flightvo.getFlightNo().substring(2));
					businessVo.setFlightTime(flightvo.getFlightStartTime());
					
					economyVo.setCompany(flightvo.getFlightNo().substring(0, 2));
					economyVo.setFlightNo(flightvo.getFlightNo().substring(2));
					economyVo.setFlightTime(flightvo.getFlightStartTime());
					Date reportDate=null;
					Date flightDate=null;
					
					try {
						reportDate =DateUtils.parseDate(DateUtils.formatDay(new Date(), "yyyyMMdd"), "yyyyMMdd");
						flightDate=DateUtils.parseDate(times.get(0), "yyyyMMdd");
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					//+0/+1 官网价格
					AirChinaDomesticEntity airChinaDomesticEntity =new AirChinaDomesticEntity();
					List<AirChinaDomesticEntity> listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(),null, sourceEntity.getHbaseKey());
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setPrice_1(en.getPrimePrice());
						businessVo.setPrice_1(en.getBusinessPrice());
						economyVo.setPrice_1(en.getEconomyPrice());
					}
					if(null == primeAirVo.getPrice_1()){
						primeAirVo.setPrice_1(0.0);
					}
					if(null == businessVo.getPrice_1()){
						businessVo.setPrice_1(0.0);
					}
					if(null == economyVo.getPrice_1()){
						economyVo.setPrice_1(0.0);
					}
					
					//+0/+1 携程价格
					listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(), null, "00003");
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setCtripPrice_1(en.getPrimePrice());
						businessVo.setCtripPrice_1(en.getBusinessPrice());
						economyVo.setCtripPrice_1(en.getEconomyPrice());
					}
					if(null == primeAirVo.getCtripPrice_1()){
						primeAirVo.setCtripPrice_1(0.0);
					}
					if(null == businessVo.getCtripPrice_1()){
						businessVo.setCtripPrice_1(0.0);
					}
					if(null == economyVo.getCtripPrice_1()){
						economyVo.setCtripPrice_1(0.0);
					}
					
					//+0/+1 艺龙价格
					listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(), null, "00004");
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setElongPrice_1(en.getPrimePrice());
						businessVo.setElongPrice_1(en.getBusinessPrice());
						economyVo.setElongPrice_1(en.getEconomyPrice());
					}
					if(null == primeAirVo.getElongPrice_1()){
						primeAirVo.setElongPrice_1(0.0);
					}
					if(null == businessVo.getElongPrice_1()){
						businessVo.setElongPrice_1(0.0);
					}
					if(null == economyVo.getElongPrice_1()){
						economyVo.setElongPrice_1(0.0);
					}
					
					try {
						flightDate=DateUtils.parseDate(times.get(1), "yyyyMMdd");
					} catch (ParseException e1) {
						e1.printStackTrace();
					}
					
					//+4 官网价格
					 airChinaDomesticEntity =new AirChinaDomesticEntity();
					 listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(),null, sourceEntity.getHbaseKey());
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setPrice_4(en.getPrimePrice());
						businessVo.setPrice_4(en.getBusinessPrice());
						economyVo.setPrice_4(en.getEconomyPrice());
					}
					if(null == primeAirVo.getPrice_4()){
						primeAirVo.setPrice_4(0.0);
					}
					if(null == businessVo.getPrice_4()){
						businessVo.setPrice_4(0.0);
					}
					if(null == economyVo.getPrice_4()){
						economyVo.setPrice_4(0.0);
					}
					
					//+4携程价格
					listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(), null, "00003");
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setCtripPrice_4(en.getPrimePrice());
						businessVo.setCtripPrice_4(en.getBusinessPrice());
						economyVo.setCtripPrice_4(en.getEconomyPrice());
					}
					if(null == primeAirVo.getCtripPrice_4()){
						primeAirVo.setCtripPrice_4(0.0);
					}
					if(null == businessVo.getCtripPrice_4()){
						businessVo.setCtripPrice_4(0.0);
					}
					if(null == economyVo.getCtripPrice_4()){
						economyVo.setCtripPrice_4(0.0);
					}
					
					//+4 艺龙价格
					listAirChina=airChinaDomesticEntity.findByCondition(reportDate, flightDate, vo.getFromCity(), vo.getToCity(), flightvo.getFlightNo(),null, "00004");
					if(null!=listAirChina && !listAirChina.isEmpty()){
						AirChinaDomesticEntity en =listAirChina.get(0);
						primeAirVo.setElongPrice_4(en.getPrimePrice());
						businessVo.setElongPrice_4(en.getBusinessPrice());
						economyVo.setElongPrice_4(en.getEconomyPrice());
					}
					if(null == primeAirVo.getElongPrice_4()){
						primeAirVo.setElongPrice_4(0.0);
					}
					if(null == businessVo.getElongPrice_4()){
						businessVo.setElongPrice_4(0.0);
					}
					if(null == economyVo.getElongPrice_4()){
						economyVo.setElongPrice_4(0.0);
					}
					
					
					listPrimeAir.add(primeAirVo);
					listBusiness.add(businessVo);
					listEconomy.add(economyVo);
					
					
					
				}
			   Map<String,List<AirChinaDemesticReportVO>> mapAir =new HashMap<String,List<AirChinaDemesticReportVO>>();
			   mapAir.put("头等舱", listPrimeAir);
			   mapAir.put("公务舱", listBusiness);
			   mapAir.put("经济舱", listEconomy);
			   map.put(data, mapAir);
		   }
		   return map;
		   
	   }
}
